//
//  BaseViewController.m
//  Running
//
//  Created by 郑东喜 on 2016/10/30.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

#import "BaseViewController.h"
#import "Encryption.h"

@interface BaseViewController ()<UITextFieldDelegate,CAAnimationDelegate>

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}


- (void)viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}



#pragma mark - keyboard movements
- (void)keyboardWillShow:(NSNotification *)notification
{
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    
    [UIView animateWithDuration:0.3 animations:^{
        CGRect f = self.view.frame;
        f.origin.y = -keyboardSize.height * 0.65;
        self.view.frame = f;
    }];
}

-(void)keyboardWillHide:(NSNotification *)notification
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect f = self.view.frame;
        f.origin.y = 0.0f;
        self.view.frame = f;
    }];
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

#pragma mark - lazy load
- (NetworkTools *)manager {
    if (!_manager) {
        _manager = [[NetworkTools alloc] init];
    }
    return _manager;
}


- (CommonTool *)tools {
    if (!_tools) {
        _tools = [[CommonTool alloc] init];
    }
    return _tools;
}



- (void)returnVC:(UIViewController *)vc {
    
//    [self.navigationController pushViewController:[LoginVC new] animated:YES];
    CATransition *caTransition = [CATransition animation];
    caTransition.duration = 0.5;
    caTransition.delegate = self;

    //    linear, easeIn, easeOut, easeInEaseOut, default
    caTransition.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];//切换速度效果

    //    kCATransitionFade, kCATransitionMoveIn
    //    kCATransitionPush, kCATransitionReveal
    caTransition.type = kCATransitionFade;//动画切换风格

    //    kCATransitionFromRight, kCATransitionFromLeft
    //    kCATransitionFromTop, kCATransitionFromBottom
    caTransition.subtype = kCATransitionFromRight;//动画切换方向

    [self.navigationController pushViewController:vc animated:YES];
    [self.navigationController.view.layer addAnimation:caTransition forKey:@"animation"];
    
    NSLog(@"%s  %d  ",__func__,__LINE__);
    
}




@end
